package com.kintreda.ieco_server.module.order.web;

import com.kintreda.ieco_server.bean.massage.Massage;
import com.kintreda.ieco_server.bean.order.Wallte;
import com.kintreda.ieco_server.core.web.R;
import com.kintreda.ieco_server.module.account.service.IUserService;
import com.kintreda.ieco_server.module.api.service.IMassageService;
import com.kintreda.ieco_server.module.order.service.IWallteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Created by IntelliJ IDEA
 * @Project_Name ieco_server
 * @Package com.kintreda.ieco_server.module.order.web
 * @Author ZhongYao_H
 * @Date 2019/5/26:21:20
 * @Year 2019 Month 05 Day 26
 * @Date_zh 2019 年 五月 星期日
 */
@Controller
@RequestMapping("/wallte")
public class WallteController {


    @Autowired
    IWallteService wallteService;
    @Autowired
    IMassageService massageService;
    @Autowired
    IUserService userService;

    @RequestMapping("/list")
    public ModelAndView list(){
    return new ModelAndView("wallte/wallte-list");
    }

    @RequestMapping(value = "/query",method = RequestMethod.POST)
    @ResponseBody
    public Object query(){
    return     wallteService.query("from Wallte where status = ? order by createDate ",new Object[]{"0"});

    }

    @RequestMapping("/detalis")
    public ModelAndView detalis(String id){
        ModelAndView andView = new ModelAndView("wallte/wallte-details");
        andView.addObject("wallte",wallteService.get(id));
        andView.addObject("user",userService.get(wallteService.get(id).getUserId()));
        return andView;
    }

    @RequestMapping(value = "/dispose",method = RequestMethod.POST)
    @ResponseBody
    public Object dispose(String id){
        Wallte wallte = wallteService.get(id);
        wallte.setStatus("1");
        Massage massage = new Massage();
        massage.setDestination(wallte.getUserId());
        massage.setTitle("打款通知");
        massage.setStatus("0");
        massage.setBody("您的提现"+wallte.getMoney().toString()+"元申请已打款");
        massageService.save(massage);
        wallteService.update(wallte);
        return R.ok("操作成功!");
    }

    @RequestMapping(value = "/reply")
    public ModelAndView reply(String id){
        ModelAndView andView = new ModelAndView("wallte/wallte-turn");
        andView.addObject("id",id);
        return andView;
    }

    @RequestMapping(value = "/reply",method = RequestMethod.POST)
    @ResponseBody
    public Object reply(String id,String msg){

        wallteService.back(id,msg);
        Wallte wallte = wallteService.get(id);
        wallte.setStatus("3");
        Massage massage = new Massage();
        massage.setDestination(wallte.getUserId());
        massage.setTitle("提现申请被驳回");
        massage.setStatus("0");
        massage.setBody(msg);
        massageService.save(massage);
        wallteService.update(wallte);
        return R.ok("操作成功");
    }








}
